<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-tabs v-model="tabs.activeKey">
      <a-tab-pane tab="活动明细" :key="tabs.globalact.key"  forceRender>
        <tpm-audit-act-list  :tempUuid="form.tempUuid" v-if="tabs.activeKey === tabs.globalact.key"></tpm-audit-act-list>
      </a-tab-pane>
      <a-tab-pane tab="销售数据" :key="tabs.globalexec.key" >
        <tpm-sales-list  :tempUuid="form.tempUuid" v-if="tabs.activeKey === tabs.globalexec.key"></tpm-sales-list>
      </a-tab-pane>
      <a-tab-pane tab="核销申请" :key="tabs.globalaudit.key" >
        <tpm-audit-act-detail-list  :tempUuid="form.tempUuid"
                                    :auditDl="model"
                                    @auditobj="getChageModel"
                                    v-if="tabs.activeKey === tabs.globalaudit.key"></tpm-audit-act-detail-list>
      </a-tab-pane>
    </a-tabs>
  </j-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import TpmAuditActDetailList from '../TpmAuditActDetailList'
  import TpmAuditActList from '../TpmAuditActList'
  import { PageListMixin } from '@/mixins/PageListMixin'
  import TpmSalesList from '../TpmSalesList'
  import lodash from 'lodash'
  export default {
    name: "TpmAuditModal",
    mixins:[PageListMixin],
    components: { TpmSalesList, TpmAuditActList,TpmAuditActDetailList },
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        tabs: {
          activeKey: 'globalact',
          globalact: {
            key: 'globalact',
          },
          globalaudit: {
            key: 'globalaudit',
          },
          globalexec:{
            key: 'globalexec'
          }
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {
          add: window._CONFIG['domianTpmURL']+"/audit/tpmAudit/saveOrUpdate",
          edit: window._CONFIG['domianTpmURL']+"/audit/tpmAudit/saveOrUpdate",
        },
      }
    },
    created () {
    },
    methods: {
      getChageModel(mObj){
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(mObj,'auditCode','auditName','remarks'))
          this.model.auditName =mObj.auditName
        });
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        if (record.tempUuid == undefined || record.tempUuid == ''){
          record.tempUuid = this.generateUUID(false);
        }
        this.form.tempUuid = record.tempUuid
        this.model.tempUuid = record.tempUuid
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'post';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>
